﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class RotateMove : MonoBehaviour {

	public Vector3 basePoint = new Vector3(0, -800, 0);

	public float radius = 300f;

	public float rotateAngle = 0;

	public static float rotateSpeed = 0.04f;

	bool isChecked = true;

	IslandLogic islandLogic;

	// Use this for initialization
	void Start () 
	{
		islandLogic = GetComponent<IslandLogic>();
	}
	
	// Update is called once per frame
	void Update () 
	{
		UpdateRotatePos();

		CheckRotate();
	}

	void CheckRotate()
	{
		if(!isChecked && rotateAngle > 30)
		{
			islandLogic.CheckNeedLowHealth();
			isChecked = true;
		}
	}

	void UpdateRotatePos()
	{
		rotateAngle += 360 * rotateSpeed * Time.deltaTime;

		if(rotateAngle > 360)
		{
			rotateAngle = rotateAngle - 360f;
			isChecked = false;
		}

		float xPos = radius * Mathf.Sin(rotateAngle / 180 * Mathf.PI);
		float yPos = radius * Mathf.Cos(rotateAngle / 180 * Mathf.PI);

		transform.localPosition = new Vector3(basePoint.x + xPos, basePoint.y + yPos, 0);
		transform.localEulerAngles = new Vector3(0, 0, 360 - rotateAngle);
	}
}
